/*
 * Copyright (c) 2006, 2023, webrx.cn All rights reserved.
 *
 */
package cn.reg;

import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * <p>Project: jse2302 - Ex5
 * <p>Powered by webrx On 2023-06-20 14:59:59
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Ex5 {
    public static void main(String[] args) {
        while (true) {
            String s = get();
            if (sum(s) == 100) {
                System.out.println(s + "=" + sum(s));
                System.out.println();
                break; //
            }

        }
    }

    public static int sum(String str) {
        int sum = 0;
        //建立Pattern类的对象实例
        Pattern p = Pattern.compile("-?\\d+");
        Matcher m = p.matcher(str);
        while (m.find()) {
            sum += Integer.parseInt(m.group());
        }
        return sum;
    }

    public static String get() {
        StringBuilder sbu = new StringBuilder();
        Random rand = new Random();
        String[] ops = {"", "-", "+"};
        for (int i = 1; i < 9; i++) {
            int len = ops.length;//3
            int pos = rand.nextInt(len); //pos = 0 1 2
            String op = ops[pos];
            String ss = i + op;
            sbu.append(ss);
        }
        sbu.append("9");
        return sbu.toString();
    }
}
